package com.xxxx.crm.controller;

import com.xxxx.crm.annoation.RequiredPermission;
import com.xxxx.crm.base.BaseController;
import com.xxxx.crm.base.ResultInfo;
import com.xxxx.crm.query.CustomerOrderQuery;
import com.xxxx.crm.service.CustomerLinkmanService;
import com.xxxx.crm.vo.CustomerLinkman;
import com.xxxx.crm.vo.CustomerOrder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

@RequestMapping("linkman")
@Controller
public class CustomerLinkmanController extends BaseController {
    @Resource
    private CustomerLinkmanService customerLinkmanService;

    /**
     * 分页多条件查询客户订单列表
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> queryCustomerLinkmanByParams(CustomerOrderQuery customerLinkmanQuery) {
        return customerLinkmanService.queryCustomerLinkmanByParams(customerLinkmanQuery);
    }

    /**
     * 进入添加/修改订单信息页面
     */
    @RequestMapping("toAddOrUpdateCustomerLinkmanPage")
    public String toAddOrUpdateCustomerOrderPage(Model model, Integer cId, Integer id) {
        // 将客户ID设置到请求域中，给计划项页面获取
        model.addAttribute("cId", cId);
        // 通过联系人ID查询记录
        CustomerLinkman customerLinkman = customerLinkmanService.selectByPrimaryKey(id);
        // 将计划项数据设置到请求域中
        model.addAttribute("customerLinkman", customerLinkman);
        return "customer/linkmanAdd_update";
    }

    /**
     * 添加计划项
     */
    @PostMapping("add")
    @ResponseBody
    public ResultInfo addCustomerLinkman(CustomerLinkman customerLinkman) {
        customerLinkmanService.addCustomerLinkman(customerLinkman);
        return success("联系人信息添加成功！");
    }

    /**
     * 更新计划项
     */
    @PostMapping("update")
    @ResponseBody
    public ResultInfo updateCustomerOrder(CustomerLinkman customerLinkman) {
        customerLinkmanService.updateCustomerLinkman(customerLinkman);
        return success("联系人信息更新成功！");
    }


    /**
     * 删除联系人（多）
     */
    @PostMapping("delete")
    @ResponseBody
    public ResultInfo deleteCustomerLinkman(Integer[] ids) {
        // 调用Service层的删除方法
        customerLinkmanService.deleteCustomerLinkman(ids);
        return success("联系人数据删除成功！");
    }
}
